package com.pmcc.cj.service;

import com.pmcc.cj.entity.CjAreaAgency;
import com.pmcc.cj.entity.CjCustomer;
import com.pmcc.cj.repository.CjAreaAgencyRepository;
import com.pmcc.cj.repository.CjCustomerRepository;
import com.pmcc.utils.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created by tomas on 2020/10/27.
 */
@Transactional
@Service
public class TestService {
    @Autowired
    CjAreaAgencyRepository cjAreaAgencyRepository;
    @Autowired
    CjCustomerRepository cjCustomerRepository;

    public ResultBean updateAreaAgency(){
        ResultBean resultBean = new ResultBean(ResultBean.SUCCESS);
        try {
            List<CjAreaAgency> list=cjAreaAgencyRepository.findAll();
            if(list != null && list.size()>0){
                for(CjAreaAgency areaAgency:list){
                    areaAgency.setEmployeeId(null);
                    areaAgency.setEmployee(null);
                    areaAgency.setUseDate(null);
                    areaAgency.setBoActive(false);
                    cjAreaAgencyRepository.saveAndFlush(areaAgency);
                }
            }
        }catch (Exception e){
            resultBean.setResultCode(ResultBean.FAIL);
        }
        return resultBean;
    }

    public ResultBean updateCustomer(){
        ResultBean resultBean =new ResultBean(ResultBean.SUCCESS);
        try {
            List<CjCustomer> list=cjCustomerRepository.findAll();
            if(list != null && list.size()>0){
                for(CjCustomer customer: list){
                    customer.setCity(null);
                    customer.setCardName(null);
                    customer.setCardAuth(false);
                    customer.setDriverAuth(false);
                    customer.setRetailer(0);
                    customer.setProxy(0);
                    customer.setProvince(null);
                    customer.setCity(null);
                    customer.setCounty(null);
                    customer.setTownship(null);
                    customer.setVillage(null);
                    customer.setAddress(null);
                    customer.setCellphone(null);
                    customer.setIntegral(null);
                    customer.setPayFlag(0);
                    customer.setRobotFlag(0);
                    customer.setMoney(new BigDecimal("0"));
                    customer.setFreezeMoney(new BigDecimal("0"));
                    cjCustomerRepository.saveAndFlush(customer);
                }
            }
        }catch (Exception e){
            resultBean.setResultCode(ResultBean.FAIL);
        }
        return resultBean;
    }
}
